﻿using Beway.ValueAdded.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Beway.ValueAdded.Admin.Controllers {
	public class ReportController : Controller {
        //
        // GET: /Report/
        /// <summary>
        /// 报表服务类
        /// </summary>
        public ReportServ RepServ = SingletonProvider<ReportServ>.Instance;
        public AdminUserServ admSvc = SingletonProvider<AdminUserServ>.Instance;

        public ActionResult ReportChart() {
			return View();
		}
		/// <summary>
		/// 获取所有启用的商户报表数据
		/// </summary>
		/// <param name="beginTime"></param>
		/// <param name="endTime"></param>
		/// <returns></returns>
		public JsonResult GetReportJson(DateTime? beginTime, DateTime? endTime) {
			if (beginTime == null && endTime == null) {
				beginTime = DateTime.Now;
				endTime = DateTime.Now;
			}
            int adminId = 0;
            if (Session["role"].ToString() == "1")
            {
                adminId = admSvc.GetByUserName(User.Identity.Name).AdminID;
            }
            var q = RepServ.GetReportData(beginTime, endTime, adminId);

           
			int ListCount = 0;
			Dictionary<string, object> json = new Dictionary<string, object>();
			json.Add("total", ListCount);
			json.Add("rows", q);
			return Json(json, JsonRequestBehavior.AllowGet);
		}
		/// <summary>
		/// 加载具体类型报表页
		/// </summary>
		/// <param name="rcType">充值类型</param>
		/// <param name="userId">商户ID</param>
		/// <param name="userTitle">商户名称</param>
		/// <returns></returns>
		public ActionResult ReportDetail(string rcType, string userId, string userTitle) {
			ViewBag.rcType = rcType;
			ViewBag.userId = userId;
			ViewBag.userTitle = userTitle;
			return View();
		}
		/// <summary>
		/// 获取具体类型的报表数据
		/// </summary>
		/// <param name="rcType">充值类型</param>
		/// <param name="userId">商户ID</param>
		/// <param name="beginTime"></param>
		/// <param name="endTime"></param>
		/// <returns></returns>
		public JsonResult GetReportDetails(string rcType, string userId, DateTime? beginTime, DateTime? endTime) {
			var q = RepServ.QueryReportDetails(rcType, userId, beginTime, endTime);
			int ListCount = 0;
			Dictionary<string, object> json = new Dictionary<string, object>();
			json.Add("total", ListCount);
			json.Add("rows", q);
			return Json(json, JsonRequestBehavior.AllowGet);
		}

	}
}
